﻿@using NetCore.Model;
@model UserEntity
    @{ 
        ViewData["Title"] = "通行证";
        string bindType = (ViewData["BindType"]==null?"0": ViewData["BindType"].ToString());

        bool flagRegister =  bindType.Equals("0");
        Layout = "_AccountLayout";
    }
<div class="middle-box text-center animated fadeInDown" style="max-width:600px;padding:0 50px;margin-top:20px;background:white;">
    <div class="row">
    <h3>&nbsp;</h3>
        <h3> @ApplicationEnvironments.ApplicationName  通行证</h3>
        @*<p><span>绑定帐号</span>您已成功验证了 @ViewBag.OAuthName 帐号！马上绑定帐号，下次登录更便捷哦 </p>*@
        <div class="col-md-12">
            <div class="tabs-container">
                <ul class="nav nav-tabs">
                    <li class="@(flagRegister?"active":"")"><a data-toggle="tab" href="#tab-1"> 您已有账号</a></li>
                    <li class="@(!flagRegister?"active":"")"><a data-toggle="tab" href="#tab-2">您没有帐号</a></li>
                </ul>
                <div class="tab-content">
                    <div id="tab-1" class="tab-pane @(flagRegister?"active":"")">
                        <div class="ibox-content">
                            <form asp-controller="Account" id="login-dynamic-form" asp-action="Login" asp-route-returnurl="@ViewData["ReturnUrl"]" method="post" class="form-horizontal" role="form">
                                <div asp-validation-summary="@ValidationSummary.All" class="text-danger"></div>
                                <div class="form-group">
                                    <label asp-for="UserName" class="col-md-3 control-label text-right">账  号</label>
                                    <div class="col-md-9">
                                        <i class="input-icon fa fa-user"></i>
                                        <input asp-for="UserName" id="txtUserName" validate="{required:true,minlength:4,maxlength:16,stringEn:true}" maxlength="16" class="form-control" placeholder="账号/邮箱/手机号" />
                                        <span asp-validation-for="UserName" class="text-danger"></span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label asp-for="Password" class="col-md-3 control-label text-right">密  码</label>
                                    <div class="col-md-9">
                                        <input asp-for="Password" id="txtPassword" type="password" class="form-control" validate="{required:true,minlength:6,maxlength:16,stringEn:true}" maxlength="16" />
                                        <i class="input-icon fa fa-lock"></i>
                                        <span asp-validation-for="Password" class="text-danger"></span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-3 control-label text-right"></label>
                                    <div class="  col-md-9">
                                        <div class="input-group m-b">
                                            <div class="i-checks">
                                                <label asp-for="RememberMe" class="i-checkbox"><input class="checkbox" asp-for="RememberMe" type="checkbox" /><span style="float:right;">Remember Me</span>  </label>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">

                                    <div class="col-md-12">
                                        <button type="submit" class="btn btn-primary block full-width m-b">登  录</button>
                                    </div>
                                </div>
                                <p class="text-muted text-center">
                                    <a asp-controller="Account" asp-action="ForgotPassword">Forgot your password?</a>
                                </p>
                            </form>
                        </div>
                        
                    </div>
                    <div id="tab-2" class="tab-pane @(!flagRegister?"active":"")">
                        <div class="ibox-content">
                            @*@Url.Content("~/oauth/account/Connect/" + ViewBag.OAuthType + "/" + ViewBag.OAuthToken + "/" + ViewBag.Token)/0*@
                            <form asp-controller="Account" id="register-dynamic-form" asp-action="Register" asp-route-returnurl="@ViewData["ReturnUrl"]" method="post" class="form-horizontal" role="form">
                                <div asp-validation-summary="@ValidationSummary.All" class="text-danger"></div>
                                <div class="form-group">
                                    <label asp-for="UserName" class="col-md-3 control-label text-right">账  号</label>
                                    <div class="col-md-9">
                                        <i class="input-icon fa fa-user"></i>
                                        <input asp-for="UserName" validate="{required:true,maxlength:16,validuser:true,remote:'../account/ChkUserName'}" maxlength="16" class="form-control" placeholder="账号只以字母开头长度6-16的字母和数字,必填！" />

                                        <span asp-validation-for="UserName" class="text-danger"></span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label asp-for="RealName" class="col-md-3 control-label text-right">姓  名</label>
                                    <div class="col-md-9">
                                        <i class="input-icon fa fa-user"></i>
                                        <input asp-for="RealName" validate="{required:true,maxlength:20}" maxlength="20" class="form-control" placeholder="请输入您的真实姓名,必填！" />
                                        <span asp-validation-for="RealName" class="text-danger"></span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label asp-for="Phone" class="col-md-3 control-label text-right">手  机</label>
                                    <div class="col-md-9">
                                        <i class="input-icon fa fa-phone"></i>
                                        <input asp-for="Phone" validate="{required:true,maxlength:11,phoneUS:true,remote:'../account/ChkPhone'}" maxlength="11" class="form-control" placeholder="只能为11位的有效数字，必填！" />
                                        <span asp-validation-for="Phone" class="text-danger"></span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label asp-for="Email" class="col-md-3 control-label text-right">Email</label>
                                    <div class="col-md-9">
                                        <div class="input-group m-b">
                                            <input asp-for="Email" validate="{required:true,email:true,remote:'../account/ChkEmail'}" class="form-control " placeholder="请输入未在平台注册过并能访问的邮箱" />
                                            <div class="input-group-btn ">
                                                <button class="btn btn-white" type="button" id="activate_email_btn">获取验证码</button>
                                            </div>

                                        </div>
                                        <span asp-validation-for="Email" class="text-danger"></span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="Verifycode" class="col-md-3 control-label text-right">验证码</label>
                                    <input type="hidden" id="txtVerifycode" name="txtVerifycode" value="1" />
                                    <div class="col-md-9">
                                        <i class="input-icon fa fa-reddit-square"></i>
                                        <input name="Verifycode" id="Verifycode" validate="{required:true}" maxlength="6" class="form-control" placeholder="请输入您的邮箱的验证码！" />

                                        <span class="text-danger field-validation-valid"></span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label asp-for="Password" class="col-md-3 control-label text-right">密  码</label>
                                    <div class="col-md-9">
                                        <input asp-for="Password" type="password" class="form-control" validate="{required:true,minlength:6,maxlength:16,stringEn:true}" maxlength="16" />
                                        <i class="input-icon fa fa-lock"></i>
                                        <span asp-validation-for="Password" class="text-danger"></span>
                                    </div>
                                </div>
                                <div class="form-group">

                                    <div class="col-md-offset-1 col-md-9">
                                        <div class="i-checks">
                                            <label for="chkAgreement" class="i-checkbox"><input id="chkAgreement" class="checkbox" name="chkAgreement" type="checkbox" /><span style="float:right;">我同意并遵守<a href="javascript://">《用户协议》</a></span>  </label>
                                        </div>
                                    </div>

                                </div>

                                <div class="form-group">
                                    <div class="col-md-offset-2 col-md-10">
                                        <button type="submit" class="btn btn-primary block full-width m-b">注  册</button>
                                    </div>
                                </div>

                            </form>


                        </div>
                    </div>
                </div>

            </div>
        </div>

    </div><!-- /.row -->
</div>
@section scripts
{


            <!-- inline scripts related to this page -->
            <script type="text/javascript">
                $("#register-dynamic-form").CustomForm({ IsValidate :true});
                $("#login-dynamic-form").CustomForm({ IsValidate: true });
                $(function () {
                   $("#activate_email_btn").click(function () {
                       if ($("#register-dynamic-form").validate().element($("#Email"))) {

                            $("#activate_email_btn").attr("time", "60");
                            var time = parseInt($("#activate_email_btn").attr("time"));
                            var winInterval = window.setInterval(function () {
                                time = time - 1;
                                $("#activate_email_btn").html("获取激活码(" + time + ")");
                                if (time <= 0) {
                                    $("#activate_email_btn").removeAttr("disabled");
                                    $("#activate_email_btn").html("获取激活码");
                                    window.clearInterval(winInterval);
                                }
                            }, 1000);
                            $("#activate_email_btn").attr("disabled", "disabled");
                            $.ajax({
                                url: "@Url.Action("chkEmail")",
                                type:"POST",
                                data: { email: $("#Email").val(), IsNotExist:"1" },
                                success: function (result) {
                                    if (result.Data && result.Data.code)
                                    {
                                        $("#txtVerifycode").val(result.Data.code);
                                    }
                                   
                                },
                                IsNoLoad: true,
                                error: function (msg) {
                                    var ele = $("#Email").parent().parent();
                                    ele.addClass("has-error");
                                    $("#Email").addClass("error");
                                    ele.find(".help-block").html(msg);
                                },
                                complete: function () {

                                }
                            });
                        }

                    });

                    $("#login-dynamic-form").submit(function () {
                        if (!$("#login-dynamic-form").valid()) {
                            return false;
                            //  alert("aa");
                        }


                    });
                    $("#register-dynamic-form").submit(function () {
                        if (!$("#register-dynamic-form").valid()) {
                            return false;
                            //  alert("aa");
                        }
                        if ($("#txtVerifycode").val().toLowerCase() != $("#Verifycode").val().toLowerCase())
                        {
                            $("#Verifycode").parent().parent().addClass("has-error");
                            $("#Verifycode").parent().parent().find(".field-validation-valid").html("验证码不正确");
                            return false;
                        }
                        if (!$("#chkAgreement")[0].checked)
                        {
                            alert("请阅读并同意用户协议");
                            return false;
                        }
                        return true;

                    });
                });
            </script>
}
